using CfgTable;
using Cysharp.Threading.Tasks;
using IQIGame.Onigao.Framework;

namespace IQIGame.Onigao.GamePlay
{
    public static class LevelDataUtil
    {
        public static bool IsEntityTag(int sign)
        {
            return sign <= ushort.MaxValue;
        }

        public static async UniTask<LevelRegionPackConfig> GetGamePlayConfig(int regionCid)
        {
            LevelRegionPackConfig cfgRegionPack = null;
            var levelPlayCtrl = LevelPlayModule.Instance.levelPlay;
            if (LevelPlayModule.Instance.inLevelPlay && levelPlayCtrl.isLocal && levelPlayCtrl.gameplayConfigsForLocal.TryGetValue(regionCid, out var pack))
            {
                cfgRegionPack = pack;
            }
            else
            {
                CfgRegionInstance cfgRegion = TableCenter.regionInstance.Get(regionCid);
                if ((GameplayAreaType)cfgRegion.GameArea != GameplayAreaType.Level)
                {
                    LogGame.LogError($"region {regionCid} 配置的GameArea不是 {(int)GameplayAreaType.Level}");
                }
                cfgRegionPack = await LevelPlayUtil.LoadRegionCfg(cfgRegion);
            }
            return cfgRegionPack;
        }
    }
}
